<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class MakerRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $createRules = [
            'name'      => 'required',
            'zone_id'   => 'required|numeric',
            'address'   => 'required',
            'mobile'    => 'sometimes|numeric',
            'if_store'  => 'required|boolean',
            'recommend' => 'required|boolean',
            'tel'       => 'required',
            'email'     => 'required|e_mail',
        ];

        $editRules = [
            'id'        => 'required|numeric',
            'name'      => 'required',
            'zone_id'   => 'required|numeric',
            'address'   => 'required',
            'mobile'    => 'sometimes|numeric',
            'if_store'  => 'required|boolean',
            'tel'       => 'required',
            'email'     => 'sometimes|e_mail',
            'recommend' => 'required|boolean',
            'status'    => 'required|in:1,-1',
        ];
//        return array();

        $data = Request::all();
        if ($data['formType'] == 'create') {
            return $createRules;
        } else {
            return $editRules;
        }
    }

    public function attributes()
    {
        $attributes = array(
            'name'      => '空间名称',
            'address'   => '地址',
            'zone_id'   => '所在地区',
            'if_store'  => '是否门店',
            'mobile'    => '用户手机号',
            'email'     => '邮箱',
            'tel'       => '电话',
            'fax'       => '传真',
            'recommend' => '是否推荐',
            'status'    => '审核状态',
        );

//        return array();
        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required'          => ':attribute为必填选项',
            'numeric'           => ':attribute必须为数字',
            'if_store.boolean'  => ':attribute必须为是门店、不是门店中的一种',
            'recommend.boolean' => ':attribute必须为是推荐、不推荐中的一种',
            'e_mail'            => ':attribute必须为合乎规范的邮箱格式',
            'status.in'         => ':attribute必须为审核通过、审核不通过中的一种',
        ];

        return $messages;
    }
}
